home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-10 | 9.5 KB | 400 lines | [TEXT/KAHL] |
- /*
- ** CAboutDialog.cp
- **
- ** About box library
- ** Dialog box class
- **
- ** Copyright © 1993, FrostByte Design / Eric Scouten
- **
- */
-
-
- #include "CAboutDialog.h"
-
- #include <Global.h>
- #include <TBUtilities.h>
- #include <CEditText.h>
- #include <CPicture.h>
- #include <string.h>
-
- #define HiNibble(_byte) ((_byte) >> 4)
- #define LoNibble(_byte) ((_byte) & 0x0F)
-
-
- // —— initialization ——
-
- /*______________________________________________________________________
- **
- ** IAboutDialog
- **
- ** Initialize the dialog. Nothing special here.
- **
- ** DLOGid (short): the resource ID
- ** anEnclosure (CDesktop *): the enclosure for the view
- ** aSupervisor (CDirector *): the view’s supervisor in the chain of command
- **
- */
-
- void CAboutDialog::IAboutDialog (short DLOGid, CDesktop *anEnclosure, CDirector *aSupervisor)
-
- {
- IDLOGDialog(DLOGid, anEnclosure, aSupervisor);
- }
-
-
- // —— special text handling functions ——
-
- /*______________________________________________________________________
- **
- ** AddDITLStatText
- **
- ** Add a static text item. Responds to standard overloaded text items. Also checks for
- ** the following special characters to be included in about box text:
- **
- **
- ** aWidth (short): width of static text item
- ** aHeight (short): height
- ** hEncl (short): position within enclosing frame
- ** vEncl (short): "" ""
- ** enclosure (CView *): enclosing frame
- ** ditlItem (tDITLItem *): the DITL item pointer
- **
- ** return (CPane *): the item which was created
- **
- */
-
- CPane *CAboutDialog::AddDITLStatText (short aWidth, short aHeight, short hEncl,
- short vEncl, CView *enclosure, tDITLItem *ditlItem)
-
- {
- CEditText *text;
- unsigned char length;
- short index;
- Str255 itemText;
- Str255 itemText2;
- Str255 tempStr;
-
-
- // first check for overloaded item (signaled by '@' in first position)
-
- if (ditlItem->itemLength != 0 && (* (char*) ditlItem->itemData) == '@') {
- length = Min(ditlItem->itemLength-1, 255);
- BlockMove(((char*) ditlItem->itemData)+1, &itemText[1], length);
- itemText[0] = length;
- return (AddOverloadedItem(itemText, aWidth, aHeight, hEncl, vEncl,
- enclosure, ditlItem));
- }
- else {
-
- // not overloaded, handle it normally
-
- text = new (CEditText);
- text->IEditText(enclosure, this, aWidth, aHeight, hEncl, vEncl,
- sizFIXEDSTICKY, sizFIXEDSTICKY, -1);
- text->Specify(kNotEditable, kNotSelectable, kNotStylable);
- text->SetFontNumber(staticTextFont);
- if (staticTextSize > 0)
- text->SetFontSize(staticTextSize);
- if (ditlItem->itemLength) {
-
- // check text for special symbols
-
- length = Min(ditlItem->itemLength, 255);
- BlockMove(((char*) ditlItem->itemData), &itemText[1], length);
- itemText[0] = length;
- itemText2[0] = 0;
- index = 1;
-
- while (index < length) {
- CollectUntilHiBit(itemText, &index, tempStr);
- ConcatPStrings(itemText2, tempStr);
- if (index < length) {
- ExpandHiBit(itemText[index], tempStr);
- ConcatPStrings(itemText2, tempStr);
- }
- index++;
- }
-
- text->SetTextPtr((Ptr) &(itemText2[1]), itemText2[0]);
- }
- return (text);
- }
-
- }
-
-
- /*______________________________________________________________________
- **
- ** AddDITLPicture
- **
- ** Add a picture item to the dialog. Overriden to substitute PICT+1 when on a black & white
- ** screen.
- **
- ** itemText (StringPtr): the text of the item
- ** aWidth (short): width of static text item
- ** aHeight (short): height
- ** hEncl (short): position within enclosing frame
- ** vEncl (short): "" ""
- ** enclosure (CView *): enclosing frame
- ** ditlItem (tDITLItem *): the DITL item pointer
- **
- ** return (CPane *): the item which was created
- **
- */
-
- CPane *CAboutDialog::AddDITLPicture (short aWidth, short aHeight, short hEncl,
- short vEncl, CView *enclosure, tDITLItem *ditlItem)
- {
- CPicture *pict = new (CPicture);
- short depth;
- short pictID;
- GDHandle theDevice;
-
-
- // determine pixel depth of main screen (where about box theoretically is…)
-
- depth = 1;
- if (IsColor()) {
- theDevice = GetMainDevice();
- depth = (**((**theDevice).gdPMap)).pixelSize;
- }
-
-
- // choose which PICT we’ll use
-
- pictID = ditlItem->itemData[0];
- if ((depth < 4) && (GetResource('PICT', pictID+1) != NULL))
- pictID++;
-
-
- // create the picture element for it
-
- pict->IPicture(enclosure, this, aWidth, aHeight, hEncl, vEncl, sizFIXEDSTICKY, sizFIXEDSTICKY);
- pict->UsePICT(pictID);
- return (pict);
-
- }
-
-
- /*______________________________________________________________________
- **
- ** AddOverloadedItem
- **
- ** Override the default overloaded item handler to provide font-changing behavior.
- ** Recognizes strings of the form "@~<font name>~<font size>".
- **
- ** itemText (StringPtr): the text of the item
- ** aWidth (short): width of static text item
- ** aHeight (short): height
- ** hEncl (short): position within enclosing frame
- ** vEncl (short): "" ""
- ** enclosure (CView *): enclosing frame
- ** ditlItem (tDITLItem *): the DITL item pointer
- **
- ** return (CPane *): the item which was created
- **
- */
-
- CPane *CAboutDialog::AddOverloadedItem (StringPtr itemText, short aWidth, short aHeight,
- short hEncl, short vEncl, CView *enclosure,
- tDITLItem *ditlItem)
-
- {
- short index;
- Str255 localText;
- Str255 fontName;
- Str255 fontSize;
- short fontNum;
- long fontSizeNum;
-
-
- BlockMove(itemText, localText, 256); // prevent memory shuffle problems
- if (localText[1] == '~') {
-
- // get font name, size
-
- PtoCstr(localText);
- index = strchr((char *) &localText[1], '~') - (char *) &localText[1];
- if ((index < 0) || (index > 254)) {
- CtoPstr((char *) localText);
- return NULL; // ignore this one
- }
- strncpy((char *) fontName, (char *) &localText[1], index);
- fontName[index] = '\0'; // don’t ask me why…
- strcpy((char *) fontSize, (char *) &localText[index+2]);
- CtoPstr((char *) fontName);
- CtoPstr((char *) fontSize);
- CtoPstr((char *) localText);
-
-
- // convert strings to usable numbers
-
- GetFontNumber(fontName, &fontNum);
- StringToNum(fontSize, &fontSizeNum);
-
- if (fontNum >= 0) { // allow two sequential strings to dictate font preference
- staticTextFont = fontNum;
- staticTextSize = (short) fontSizeNum;
- }
-
- return NULL; // no item created
-
- }
-
- else
- return (CDLOGDialog::AddOverloadedItem(localText, aWidth, aHeight, hEncl,
- vEncl, enclosure, ditlItem));
-
- }
-
-
- // —— utility procedures ——
-
- /*______________________________________________________________________
- **
- ** CollectUntilHiBit (protected method)
- **
- ** Collect characters from a string until a character is found with the high bit set.
- **
- ** text (StringPtr): pointer to the source string
- ** index (short *): where are we in the source string?
- ** returnStr (StringPtr): where to send the collected text
- **
- */
-
- void CAboutDialog::CollectUntilHiBit (StringPtr text, short *index, StringPtr returnStr)
-
- {
- short i = *index;
- short limit = Length(text);
-
- Length(returnStr) = 0;
- while (((text[i] & 0x80) == 0) && (i <= limit))
- returnStr[++returnStr[0]] = text[i++];
-
- if (i > limit)
- i = limit;
- *index = i;
- }
-
-
- /*______________________________________________________________________
- **
- ** ExpandHiBit (protected method)
- **
- ** Expand a special character with the high bit set. Responds to the following characters:
- **
- ** character replace with
- ** ----------- ---------------
- ** √ (option-V) current version number (see GetVersion)
- **
- **
- ** theChar (unsigned char): the character to expand
- ** returnStr (StringPtr): where to return the expanded string
- **
- */
-
- void CAboutDialog::ExpandHiBit (unsigned char theChar, StringPtr returnStr)
-
- {
- switch (theChar) {
-
- case (unsigned char) '√':
- GetVersion (1, returnStr);
- break;
-
- default:
- returnStr[0] = 1; // just send the character back as a string
- returnStr[1] = theChar;
- }
-
- }
-
-
- /*______________________________________________________________________
- **
- ** GetVersion (protected method)
- **
- ** Get the version number from the 'vers' resource and format it as a text version string.
- **
- ** versID (short): the 'vers' resource to read
- ** theString (Str255): where to return the text
- **
- */
-
- void CAboutDialog::GetVersion (short versID, Str255 theString)
-
- {
- Handle rsrcData;
- Str255 tempStr;
- char stageChar;
-
- short major; // version info copied from 'vers' resource
- short minor;
- short minuscule;
- short release;
- short region;
- enum {
- kDevelopmentVersion = 0x20,
- kAlphaVersion = 0x40,
- kBetaVersion = 0x60,
- kFinalVersion = 0x80
- } stage;
-
-
- // grab the resource & interpret it
-
- rsrcData = GetResource('vers', versID);
- FailNILRes(rsrcData);
-
-
- // thanks to Andrew Gilmartin for the code to read the resource
-
- major = HiNibble((*rsrcData)[0]) * 10 + LoNibble((*rsrcData)[0]);
- minor = HiNibble((*rsrcData)[1]);
- minuscule = LoNibble((*rsrcData)[1]);
-
- stage = (*rsrcData)[2];
- release = HiNibble((*rsrcData)[3]) * 10 + LoNibble((*rsrcData)[3]);
- region = *(short*) ((*rsrcData) + 4);
-
- // ignore version strings
-
- ReleaseResource(rsrcData);
-
-
- // convert version information above into textual format
-
- NumToString(major, theString);
- theString[++theString[0]] = '.'; // sorry for the hard-wiring
- NumToString(minor, tempStr);
- ConcatPStrings(theString, tempStr);
- if (minuscule) {
- theString[++theString[0]] = '.';
- NumToString(minuscule, tempStr);
- ConcatPStrings(theString, tempStr);
- }
- switch (stage) {
- case kDevelopmentVersion:
- stageChar = 'd';
- break;
- case kAlphaVersion:
- stageChar = 'a';
- break;
- case kBetaVersion:
- stageChar = 'b';
- break;
- case kFinalVersion:
- stageChar = 'v'; // version naming, Claris-style…why not?
- break;
- default:
- stageChar = '?';
- }
- if (release) {
- theString[++theString[0]] = stageChar;
- NumToString(release, tempStr);
- ConcatPStrings(theString, tempStr);
- }
-
- }
-